<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="系统用户ID" prop="sysUserId">
        <el-input
          v-model="queryParams.sysUserId"
          placeholder="请输入系统用户ID"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="用户id" prop="userid">
        <el-input
          v-model="queryParams.userid"
          placeholder="请输入用户id"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="个人名称" prop="personname">
        <el-input
          v-model="queryParams.personname"
          placeholder="请输入个人名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="证件类型编码" prop="identtypecode">
        <el-input
          v-model="queryParams.identtypecode"
          placeholder="请输入证件类型编码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="证件号码" prop="identno">
        <el-input
          v-model="queryParams.identno"
          placeholder="请输入证件号码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="邮箱" prop="email">
        <el-input
          v-model="queryParams.email"
          placeholder="请输入邮箱"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="手机号" prop="mobilephone">
        <el-input
          v-model="queryParams.mobilephone"
          placeholder="请输入手机号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="用于登录邮箱" prop="usedemaillogin">
        <el-input
          v-model="queryParams.usedemaillogin"
          placeholder="请输入用于登录邮箱"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="用于登录手机" prop="usedmobilelogin">
        <el-input
          v-model="queryParams.usedmobilelogin"
          placeholder="请输入用于登录手机"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否开通国密证书" prop="isopensm2">
        <el-input
          v-model="queryParams.isopensm2"
          placeholder="请输入是否开通国密证书"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="地址" prop="address">
        <el-input
          v-model="queryParams.address"
          placeholder="请输入地址"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="认证方式" prop="authenticationmode">
        <el-input
          v-model="queryParams.authenticationmode"
          placeholder="请输入认证方式"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="认证时间" prop="authenticationtime">
        <el-input
          v-model="queryParams.authenticationtime"
          placeholder="请输入认证时间"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="短信模板ID" prop="smstemplateid">
        <el-input
          v-model="queryParams.smstemplateid"
          placeholder="请输入短信模板ID"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="邮件模板ID" prop="emailtemplateid">
        <el-input
          v-model="queryParams.emailtemplateid"
          placeholder="请输入邮件模板ID"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="企业名称" prop="enterprisename">
        <el-input
          v-model="queryParams.enterprisename"
          placeholder="请输入企业名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="企业联系电话" prop="landlinephone">
        <el-input
          v-model="queryParams.landlinephone"
          placeholder="请输入企业联系电话"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="安心签用户邮箱" prop="anxinsignemail">
        <el-input
          v-model="queryParams.anxinsignemail"
          placeholder="请输入安心签用户邮箱"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="安心签用户手机号" prop="anxinsignmobilephone">
        <el-input
          v-model="queryParams.anxinsignmobilephone"
          placeholder="请输入安心签用户手机号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="经办人名称" prop="transactorname">
        <el-input
          v-model="queryParams.transactorname"
          placeholder="请输入经办人名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="经办人证件类型编码" prop="transactoridenttypecode">
        <el-input
          v-model="queryParams.transactoridenttypecode"
          placeholder="请输入经办人证件类型编码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="经办人证件号码" prop="transactoridentno">
        <el-input
          v-model="queryParams.transactoridentno"
          placeholder="请输入经办人证件号码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="经办人地址" prop="transactoraddress">
        <el-input
          v-model="queryParams.transactoraddress"
          placeholder="请输入经办人地址"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['base:user:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['base:user:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['base:user:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['base:user:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="userList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="经办人地址" align="center" prop="id" />
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="系统用户ID" align="center" prop="sysUserId" />
      <el-table-column label="用户id" align="center" prop="userid" />
      <el-table-column label="个人名称" align="center" prop="personname" />
      <el-table-column label="证件类型编码" align="center" prop="identtypecode" />
      <el-table-column label="证件号码" align="center" prop="identno" />
      <el-table-column label="邮箱" align="center" prop="email" />
      <el-table-column label="手机号" align="center" prop="mobilephone" />
      <el-table-column label="用于登录邮箱" align="center" prop="usedemaillogin" />
      <el-table-column label="用于登录手机" align="center" prop="usedmobilelogin" />
      <el-table-column label="是否开通国密证书" align="center" prop="isopensm2" />
      <el-table-column label="地址" align="center" prop="address" />
      <el-table-column label="认证方式" align="center" prop="authenticationmode" />
      <el-table-column label="认证时间" align="center" prop="authenticationtime" />
      <el-table-column label="短信模板ID" align="center" prop="smstemplateid" />
      <el-table-column label="邮件模板ID" align="center" prop="emailtemplateid" />
      <el-table-column label="企业名称" align="center" prop="enterprisename" />
      <el-table-column label="企业联系电话" align="center" prop="landlinephone" />
      <el-table-column label="安心签用户邮箱" align="center" prop="anxinsignemail" />
      <el-table-column label="安心签用户手机号" align="center" prop="anxinsignmobilephone" />
      <el-table-column label="经办人名称" align="center" prop="transactorname" />
      <el-table-column label="经办人证件类型编码" align="center" prop="transactoridenttypecode" />
      <el-table-column label="经办人证件号码" align="center" prop="transactoridentno" />
      <el-table-column label="经办人地址" align="center" prop="transactoraddress" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['base:user:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['base:user:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改安心签用户对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="系统用户ID" prop="sysUserId">
          <el-input v-model="form.sysUserId" placeholder="请输入系统用户ID" />
        </el-form-item>
        <el-form-item label="用户id" prop="userid">
          <el-input v-model="form.userid" placeholder="请输入用户id" />
        </el-form-item>
        <el-form-item label="个人名称" prop="personname">
          <el-input v-model="form.personname" placeholder="请输入个人名称" />
        </el-form-item>
        <el-form-item label="证件类型编码" prop="identtypecode">
          <el-input v-model="form.identtypecode" placeholder="请输入证件类型编码" />
        </el-form-item>
        <el-form-item label="证件号码" prop="identno">
          <el-input v-model="form.identno" placeholder="请输入证件号码" />
        </el-form-item>
        <el-form-item label="邮箱" prop="email">
          <el-input v-model="form.email" placeholder="请输入邮箱" />
        </el-form-item>
        <el-form-item label="手机号" prop="mobilephone">
          <el-input v-model="form.mobilephone" placeholder="请输入手机号" />
        </el-form-item>
        <el-form-item label="用于登录邮箱" prop="usedemaillogin">
          <el-input v-model="form.usedemaillogin" placeholder="请输入用于登录邮箱" />
        </el-form-item>
        <el-form-item label="用于登录手机" prop="usedmobilelogin">
          <el-input v-model="form.usedmobilelogin" placeholder="请输入用于登录手机" />
        </el-form-item>
        <el-form-item label="是否开通国密证书" prop="isopensm2">
          <el-input v-model="form.isopensm2" placeholder="请输入是否开通国密证书" />
        </el-form-item>
        <el-form-item label="地址" prop="address">
          <el-input v-model="form.address" placeholder="请输入地址" />
        </el-form-item>
        <el-form-item label="认证方式" prop="authenticationmode">
          <el-input v-model="form.authenticationmode" placeholder="请输入认证方式" />
        </el-form-item>
        <el-form-item label="认证时间" prop="authenticationtime">
          <el-input v-model="form.authenticationtime" placeholder="请输入认证时间" />
        </el-form-item>
        <el-form-item label="短信模板ID" prop="smstemplateid">
          <el-input v-model="form.smstemplateid" placeholder="请输入短信模板ID" />
        </el-form-item>
        <el-form-item label="邮件模板ID" prop="emailtemplateid">
          <el-input v-model="form.emailtemplateid" placeholder="请输入邮件模板ID" />
        </el-form-item>
        <el-form-item label="企业名称" prop="enterprisename">
          <el-input v-model="form.enterprisename" placeholder="请输入企业名称" />
        </el-form-item>
        <el-form-item label="企业联系电话" prop="landlinephone">
          <el-input v-model="form.landlinephone" placeholder="请输入企业联系电话" />
        </el-form-item>
        <el-form-item label="安心签用户邮箱" prop="anxinsignemail">
          <el-input v-model="form.anxinsignemail" placeholder="请输入安心签用户邮箱" />
        </el-form-item>
        <el-form-item label="安心签用户手机号" prop="anxinsignmobilephone">
          <el-input v-model="form.anxinsignmobilephone" placeholder="请输入安心签用户手机号" />
        </el-form-item>
        <el-form-item label="经办人名称" prop="transactorname">
          <el-input v-model="form.transactorname" placeholder="请输入经办人名称" />
        </el-form-item>
        <el-form-item label="经办人证件类型编码" prop="transactoridenttypecode">
          <el-input v-model="form.transactoridenttypecode" placeholder="请输入经办人证件类型编码" />
        </el-form-item>
        <el-form-item label="经办人证件号码" prop="transactoridentno">
          <el-input v-model="form.transactoridentno" placeholder="请输入经办人证件号码" />
        </el-form-item>
        <el-form-item label="经办人地址" prop="transactoraddress">
          <el-input v-model="form.transactoraddress" placeholder="请输入经办人地址" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listUser, getUser, delUser, addUser, updateUser, exportUser } from "@/api/base/user";

export default {
  name: "User",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 安心签用户表格数据
      userList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        sysUserId: null,
        userid: null,
        personname: null,
        identtypecode: null,
        identno: null,
        email: null,
        mobilephone: null,
        usedemaillogin: null,
        usedmobilelogin: null,
        isopensm2: null,
        address: null,
        authenticationmode: null,
        authenticationtime: null,
        smstemplateid: null,
        emailtemplateid: null,
        enterprisename: null,
        landlinephone: null,
        anxinsignemail: null,
        anxinsignmobilephone: null,
        transactorname: null,
        transactoridenttypecode: null,
        transactoridentno: null,
        transactoraddress: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询安心签用户列表 */
    getList() {
      this.loading = true;
      listUser(this.queryParams).then(response => {
        this.userList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        sysUserId: null,
        userid: null,
        personname: null,
        identtypecode: null,
        identno: null,
        email: null,
        mobilephone: null,
        usedemaillogin: null,
        usedmobilelogin: null,
        isopensm2: null,
        address: null,
        authenticationmode: null,
        authenticationtime: null,
        smstemplateid: null,
        emailtemplateid: null,
        enterprisename: null,
        landlinephone: null,
        anxinsignemail: null,
        anxinsignmobilephone: null,
        transactorname: null,
        transactoridenttypecode: null,
        transactoridentno: null,
        transactoraddress: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加安心签用户";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getUser(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改安心签用户";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateUser(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addUser(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除安心签用户编号为"' + ids + '"的数据项？').then(function() {
        return delUser(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$modal.confirm('是否确认导出所有安心签用户数据项？').then(() => {
        this.exportLoading = true;
        return exportUser(queryParams);
      }).then(response => {
        this.$download.name(response.msg);
        this.exportLoading = false;
      }).catch(() => {});
    }
  }
};
</script>
